package com.molichuxing.utils;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.services.business.dto.response.OrderScheduleReminderBizDto;
import com.molichuxing.services.business.dto.response.UserBizDto;
import com.molichuxing.services.infrastructure.dto.response.CarDto;
import com.molichuxing.services.infrastructure.dto.response.StoreDto;

public class ExcelUtil {

	/**
	 * 专属订单还款日前3天提醒邮件title
	 */
	public static final String[] EXCLUSIVEL_REPAYREMINDER_TITLE = { "订单号", "商品名称", "还款期数", "应还款金额", "下单日期", "应还款日",
			"状态", "交车门店", "车牌号", "车架号", "签约人姓名", "联系电话", "地址" };

	/**
	 * 专属订单逾期未还提醒邮件title
	 */
	public static final String[] EXCLUSIVEL_OVERDUE_TITLE = { "订单号", "商品名称", "还款期数", "应还款金额", "下单日期", "应还款日", "状态",
			"交车门店", "车牌号", "车架号", "签约人姓名", "联系电话", "地址" };


	public static XSSFWorkbook createHSSFWorkbook(String[] titles) {
		// 初始一个workbook
		XSSFWorkbook workbook = new XSSFWorkbook();
		// 创建单个sheet
		XSSFSheet sheet = workbook.createSheet("sheet0");
		// 创建第一行，设置列名
		XSSFRow row = sheet.createRow(0);
		for (int cellIndex = 0; cellIndex < titles.length; cellIndex++) {
			XSSFCell cell = row.createCell(cellIndex);
			cell.setCellValue(titles[cellIndex]);
		}

		return workbook;
	}

	public static void setExclusivelRepayReminderCellValue(XSSFRow row,
			OrderScheduleReminderBizDto orderScheduleReminderBizDto, UserBizDto userDto, CarDto carDto,
			StoreDto storeDto) {
		if (row == null) {
			return;
		}
		if (orderScheduleReminderBizDto != null) {
			// 订单号
			row.createCell(0).setCellValue(orderScheduleReminderBizDto.getOrderCode());
			// 商品名称
			row.createCell(1).setCellValue(orderScheduleReminderBizDto.getGoodsName());
			// 还款期数
			row.createCell(2).setCellValue(
					orderScheduleReminderBizDto.getPeriods() + "/" + orderScheduleReminderBizDto.getTotalPeriods());
			// 应还款金额
			row.createCell(3).setCellValue(orderScheduleReminderBizDto.getPayable().toString());
			// 下单日期
			row.createCell(4).setCellValue(DateUtil.formatDate(orderScheduleReminderBizDto.getOrderTime()));
			// 应还款日
			row.createCell(5).setCellValue(DateUtil.formatDate(orderScheduleReminderBizDto.getPayableDate()));
			// 状态
			// row.createCell(6).setCellValue(DateUtil.formatDate(orderScheduleReminderBizDto.getPayableDate()));
		}
		if (storeDto != null) {
			// 交车门店
			row.createCell(7).setCellValue(storeDto.getShortName());
		}
		if (carDto != null) {
			// 车牌号
			row.createCell(8).setCellValue(carDto.getLicencePlate());
			// 车架号
			row.createCell(9).setCellValue(carDto.getVin());
		}
		if (userDto != null) {
			// 签约人姓名
			row.createCell(10).setCellValue(userDto.getRealName());
			// 联系电话
			row.createCell(11).setCellValue(userDto.getPhone());
			// 地址
			row.createCell(12).setCellValue(userDto.getAddress());
		}
	}

}
